package org.ktjy.quartz_demo.job;

import org.quartz.*;

/**
 * @author Jane
 * @date 2024-12-11 16:19
 */

@PersistJobDataAfterExecution  //多个定时任务中共享同一个getJobDataMap的数据
@DisallowConcurrentExecution //当前定时任务没有执行完成之前,不要开始下一个任务
public class Quartz_BackUpDB implements Job {

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        JobDetail jobDetail = context.getJobDetail();
        //System.out.println("jobDetail: "+  System.identityHashCode(jobDetail));

//        System.out.println("任务名字:"+jobDetail.getKey().getName());
//        System.out.println("任务分组名称:"+jobDetail.getKey().getGroup());
//        System.out.println("任务类名字:"+jobDetail.getJobClass().getName());
//
//        System.out.println("本次执行时间:"+context.getFireTime());
//        System.out.println("下次执行时间:"+context.getNextFireTime());

        JobDataMap map = jobDetail.getJobDataMap();
        Integer count = (Integer) map.get("count");
        System.out.println(String.format("定时任务-备份数据库第%s次执行   %s",count,context.getFireTime()));
        //count++;
        map.put("count",++count);


        //休眠3秒
//        try {
//            Thread.sleep(3000);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }
        System.out.println();


    }
}
